const { getLastReport, getReportTypeList } = require('../../utils/api');
const { formatDate } = require('../../utils/tool');

Page({
  data: {
    report: {},
  },

  onLoad() {
    getReportTypeList().then((res) => {
      const typeList = (res?.data || []).map((item) => {
        return {
          dictLabel: item.dictLabel,
          dictType: item.dictType,
        };
      });
      const typeMap = typeList.reduce((acc, cur) => {
        acc[cur.dictType] = cur.dictLabel;
        return acc;
      }, {});
      this.setData({ typeMap });
    });
    getLastReport().then((res) => {
      const report = res?.data || {};
      this.setData({
        report: {
          ...report,
          createTime: formatDate(report?.createTime || ''),
          imgs: report.imgs?.split?.(',') || [],
        },
      });
    });
  },
});
